import numpy as np

a = np.arange(5)
print('一维数组a：%s' % (a))

b = np.arange(5, 10)
print('一维数组b：%s' % (b))

b2 = np.arange(10, 15)
print('一维数组b：%s' % (b))

c = np.array([a, b, b2])
print('二维数组c:')
print(c)
print('c 数组的维度：', c.shape)

c1 = np.array([a, b, b2], dtype=complex)
print('二维数组c:')
print(c1)

c1 = np.array([a, b, b2], ndmin=3)
print('二维数组c:')
print(c1)

test_arange = np.arange(0, 10, 3, dtype=complex)
print(test_arange)

x = np.random.random(size=4)
print('生成一维（4，）的随机数组：')
print(x)

x3_4 = np.random.random(size=(3, 4))
print('生成二维（3，4）的随机数组：')
print(x3_4)

print('生成随机数x_randn：')
x_randn = np.random.randn()
print(x_randn)
y = np.random.randn(2, 4)
print('生成二维（2, 4）的随机数组：')
print(y)
z = np.random.randn(2, 3, 4)
print('生成三维（2, 3, 4）的随机数组：')
print(z)

print('生成的正太分布 loc：期望 scale：方差 size 形状 数据')
print(np.random.normal(loc=100, scale=0.001, size=(5, 5)))

import numpy as np

x1 = np.random.randint(10, size=6)
print(x1)
x2 = np.random.randint(10, size=(3, 4))
print(x2)
x3 = np.random.randn(3, 4, 5)
print('ndim 属性'.center(20, '*'))
print('ndim:', x1.ndim, x2.ndim, x3.ndim)
print('shape 属性'.center(20, '*'))
print('shape:', x1.shape, x2.shape, x3.shape)
print('dtype 属性'.center(20, '*'))
print('dtype:', x1.dtype, x2.dtype, x3.dtype)
print('size 属性'.center(20, '*'))
print('size:', x1.size, x2.size, x3.size)
print('itemsize 属性'.center(20, '*'))  # 一个字节是 8 位

print('生成一个等差数列:')
x = np.linspace(20, 100, 10, endpoint=True, retstep=True, dtype=int)
print(x)

print('生成一个等比数列:')
x = np.logspace(0, 100, 10, base=2)
print(x)





x = np.arange(1, 13)
a = x.reshape(4, 3)
print('数组元素')
print(a)
print('获取第二行')
print(a[1])
print('获取第三行第二列')
print(a[2][1])
print('获取所有行的第二列：')
print(a[:, 1])
print('奇数行的第一列：')
print(a[::2, 0])
print('第一行：')
print(a[:1])
print('行列倒序：')
print(a[::-1, ::-1])

a = np.arange(1, 13).reshape(3, 4)
sub_array = a[:2, :2]
sub_array[0][0] = 1000
print(a)
print(sub_array)
print('copy'.center(20, '='))
sub_array = np.copy(a[:2, :2])
sub_array[0][0] = 2000
print('原数组：')
print(a)
print('copy数组:')
print(sub_array)



